<?php

//$order is the selected order
//$company is the company
//$contact is the contact belonging to the order
//$items is an array with material/products beloning to this order
//$materials is an array with materials required and used on this order
$document = $_POST['document'];
if($document != 'LoM'){
?>
<div style="width: 650px; margin: 0 auto; font-family:calibri;">
    <table style="border-collapse: collapse; font-size: 14px;">
        <tr>
            <td>
                <?php $path = $company->getLogo() ?>
                <img src="<?php echo image_path($path); ?>" alt="Logo"/>
            </td>    
        </tr>
        <tr>
            <td style="font-weight: bold;"><?php echo $company->getSlogan() ?></td>
        </tr>
    </table>
    <table style="border-collapse: collapse; font-size: 14px;">
        <tr height="20px"></tr>
        <tr>
            <td><?php echo $company->getName() ?></td>
            <td><?php //echo $company->getBank() ?></td>
        </tr>
        <tr>
            <td><?php echo $company->getAddress() ?></td>
            <td><?php //echo $company->getBankNo() ?></td>
        </tr>
        <tr>
            <td><?php echo $company->getZipCode().' '. $company->getCity() ?></td>
            <td><?php //echo $company->getIban() ?></td>
        </tr>
        <tr>
            <td><?php echo $company->getCountry() ?></td>
            <td><?php //echo $company->getBic() ?></td>
        </tr>
        <tr>
            <td></td>
            <td><?php //echo $company->getBtwNo() ?></td>
        </tr>
        <tr>
            <td><?php echo $company->getEmail() ?></td>
            <td><?php //echo $company->getKvk() ?></td>
        </tr>
        <tr>
            <td><?php echo $company->getPhone() ?></td>
        </tr>
        <tr>
            <td><?php echo $company->getFax() ?></td>
        </tr>
        <tr height="20px"></tr>
    </table>
    <?php
    
    if($document == 'Quo'){ //Show Quotation
        ?>
        <table style="border-collapse: collapse; font-size: 14px;">
            <tr colspan="5">
                <td style="font-size: 30px;"><strong>Quotation</strong></td>
            </tr>
            <tr><td height="40px"></td></tr>
            <tr>
                <td width="325px"><strong>For:</strong></td>
                <td></td>
            </tr>
            <tr>
                <td><?php echo $contact->getName() ?></td>
                <td></td>
            </tr>
            <tr>
                <td><?php echo $contact->getAddress() ?></td>
                <td></td>		
            </tr>
            <tr>
                <td><?php echo $contact->getZipCode().' '.$contact->getCity() ?></td>
                <td></td>
            </tr>
            <tr>
                <td><?php echo $contact->getCountry() ?></td>
                <td></td>
            </tr>
            <tr height="10px">
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td><strong>Phone: </strong><?php echo $contact->getPhone() ?></td>
                <td></td>
            </tr>
            <tr>
                <td><strong>Mobile: </strong><?php echo $contact->getMobile() ?></td>
                <td></td>
            </tr>
            <tr height="10px">
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td><strong>Quotation no: </strong><?php echo $order->getId() ?></td>
                <td><strong>Own No: </strong><?php echo $order->getCOrderNumber() ?></td>
            </tr>
            <tr>
                <td><strong>Date in: </strong><?php echo $order->getDateRecieved() ?></td>
                <td></td>
            </tr>
            <tr height="20px"></tr>
        </table>
        <table style="border-collapse: collapse; font-size: 12px;">
            <tr style="border-top: 1px solid black; border-bottom: 1px solid black; font-weight: bold; font-size: 15px; text-align: right;">
                <td width="360px" style="text-align: left;">Product</td>
                <td width="70px">Quantity</td>
                <td width="70px">Price</td>
                <td width="80px">Discount(%)</td>
                <td width="70px">Total Price</td>
            </tr>
        <?php foreach($items as $item) {
            echo '<tr style="text-align: right;">';
            echo '<td style="text-align: left;">'.$item->getName().'</td>';
            echo '<td>'.$item->getAmount().'</td>';
            echo '<td>'.$item->getPrice().'</td>';
            echo '<td>'.$item->getDiscount().'</td>';
            $total_discount = $item->getDiscount() * $item->getPrice();
            $total_price_product = $item->getAmount() * $item->getPrice() - $total_discount;
            echo '<td>'.$total_price_product.'</td>';
            echo '</tr>';
            //calculate total price
            if(!isset($total_price_order)){ $total_price_order = 0; }
            $total_price_order = $total_price_order + $total_price_product;
            //calculate taxes
            $tax = $item->getVAT();
            $tax_dec = '0.'.$tax; //tax in decimals
            $tax_product = $item->getPrice() * $tax_dec; //tax for 1 product
            $tax_total_products = $item->getAmount() * $tax_product;//tax over all products
            if(!isset($total_tax)){ $total_tax = 0; }
            $total_tax = $total_tax + $tax_total_products;
        } ?>
        <tr height="20px"></tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>	
            <td>Subtotal</td>
            <td style="border-top: 1px solid black; text-align: right;"><?php echo $total_price_order ?></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td>VAT</td>
            <td style="text-align: right;"><?php echo $total_tax ?></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>	
            <td>Total</td>
            <td style="border-top: 1px solid black; text-align: right;"><?php echo $total_price_order + $total_tax ?></td>
        </tr>
        </table>
        <?php
    }
    if($document == 'CoO'){
        //Show Confirmation of Order
        ?>
        <table style="border-collapse: collapse; font-size: 14px;">
            <tr colspan="5">
                <td style="font-size: 30px;"><strong>Order Confirmation</strong></td>
            </tr>
            <tr><td height="40px"></td></tr>
            <tr>
                <td width="325px"><strong>By:</strong></td>
                <td><strong>Shipping to:</strong></td>
            </tr>
            <tr>
                <td><?php echo $contact->getName() ?></td>
                <td><?php echo $order->getShipLastname().' '.$order->getShipFirstname()?></td>
            </tr>
            <tr>
                <td><?php echo $contact->getAddress() ?></td>
                <td><?php echo $order->getShipAddress() ?></td>		
            </tr>
            <tr>
                <td><?php echo $contact->getZipCode().' '.$contact->getCity() ?></td>
                <td><?php echo $order->getShipZipcode().' '.$order->getShipCity() ?></td>
            </tr>
            <tr>
                <td><?php echo $contact->getCountry() ?></td>
                <td><?php echo $order->getShipCountry() ?></td>
            </tr>
            <tr height="10px">
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td><strong>Phone: </strong><?php echo $contact->getPhone() ?></td>
                <td></td>
            </tr>
            <tr>
                <td><strong>Mobile: </strong><?php echo $contact->getMobile() ?></td>
                <td></td>
            </tr>
            <tr height="10px">
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td><strong>Order no: </strong><?php echo $order->getId() ?></td>
                <td><strong>Own No: </strong><?php echo $order->getCOrderNumber() ?></td>
            </tr>
            <tr>
                <td><strong>Date in: </strong><?php echo $order->getDateRecieved() ?></td>
                <td></td>
            </tr>
            <tr height="20px"></tr>
    </table>
    <table style="border-collapse: collapse; font-size: 12px;">
            <tr style="border-top: 1px solid black; border-bottom: 1px solid black; font-weight: bold; font-size: 15px; text-align: right;">
                <td width="360px" style="text-align: left;">Product</td>
                <td width="70px">Quantity</td>
                <td width="70px">Price</td>
                <td width="80px">Discount(%)</td>
                <td width="70px">Total Price</td>
            </tr>
        <?php foreach($items as $item) {
            echo '<tr style="text-align: right;">';
            echo '<td style="text-align: left;">'.$item->getName().'</td>';
            echo '<td>'.$item->getAmount().'</td>';
            echo '<td>'.$item->getPrice().'</td>';
            echo '<td>'.$item->getDiscount().'</td>';
            $total_discount = $item->getDiscount() * $item->getPrice();
            $total_price_product = $item->getAmount() * $item->getPrice() - $total_discount;
            echo '<td>'.$total_price_product.'</td>';
            echo '</tr>';
            //calculate total price
            if(!isset($total_price_order)){ $total_price_order = 0; }
            $total_price_order = $total_price_order + $total_price_product;
            //calculate taxes
            $tax = $item->getVAT();
            $tax_dec = '0.'.$tax; //tax in decimals
            $tax_product = $item->getPrice() * $tax_dec; //tax for 1 product
            $tax_total_products = $item->getAmount() * $tax_product;//tax over all products
            if(!isset($total_tax)){ $total_tax = 0; }
            $total_tax = $total_tax + $tax_total_products;
        } ?>
            <tr height="20px"></tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>	
            <td>Subtotal</td>
            <td style="border-top: 1px solid black; text-align: right;"><?php echo $total_price_order ?></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td>VAT</td>
            <td style="text-align: right;"><?php echo $total_tax ?></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>	
            <td>Total</td>
            <td style="border-top: 1px solid black; text-align: right;"><?php echo $total_price_order + $total_tax ?></td>
        </tr>
        </table>
        <?php
    }
    if($document == 'Ord'){
        //Show Order
        ?>
        <table style="border-collapse: collapse; font-size: 14px;">
            <tr colspan="5">
                <td style="font-size: 30px;"><strong>Order</strong></td>
            </tr>
            <tr><td height="40px"></td></tr>
            <tr>
                <td width="325px"><strong>By:</strong></td>
                <td><strong>Shipping to:</strong></td>
            </tr>
            <tr>
                <td><?php echo $contact->getName() ?></td>
                <td><?php echo $order->getShipLastname().' '.$order->getShipFirstname()?></td>
            </tr>
            <tr>
                <td><?php echo $contact->getAddress() ?></td>
                <td><?php echo $order->getShipAddress() ?></td>		
            </tr>
            <tr>
                <td><?php echo $contact->getZipCode().' '.$contact->getCity() ?></td>
                <td><?php echo $order->getShipZipcode().' '.$order->getShipCity() ?></td>
            </tr>
            <tr>
                <td><?php echo $contact->getCountry() ?></td>
                <td><?php echo $order->getShipCountry() ?></td>
            </tr>
            <tr height="10px">
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td><strong>Phone: </strong><?php echo $contact->getPhone() ?></td>
                <td></td>
            </tr>
            <tr>
                <td><strong>Mobile: </strong><?php echo $contact->getMobile() ?></td>
                <td></td>
            </tr>
            <tr height="10px">
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td><strong>Order no: </strong><?php echo $order->getId() ?></td>
                <td><strong>Own No: </strong><?php echo $order->getCOrderNumber() ?></td>
            </tr>
            <tr>
                <td><strong>Date in: </strong><?php echo $order->getDateRecieved() ?></td>
                <td></td>
            </tr>
            <tr height="20px"></tr>
    </table>
    <table style="border-collapse: collapse; font-size: 12px;">
         <tr style="border-top: 1px solid black; border-bottom: 1px solid black; font-weight: bold; font-size: 15px; text-align: right;">
                <td width="580px" style="text-align: left;">Product</td>
                <td width="70px">Quantity</td>
            </tr>
        <?php foreach($items as $item) {
            echo '<tr>';
            echo '<td>'.$item->getName().'</td>';
            echo '<td style="text-align:right;">'.$item->getAmount().'</td>';
        } ?>
        <tr height="20px"></tr>
        </table>
        <?php
    }
    if($document == 'PS'){
        //Show Production Sheet
        ?>
        <table style="border-collapse: collapse; font-size: 14px;">
            <tr colspan="5">
                <td style="font-size: 30px;"><strong>Production Sheet</strong></td>
            </tr>
            <tr><td height="40px"></td></tr>
            <tr>
                <td><strong>Order no: </strong><?php echo $order->getId() ?></td>
            </tr>
            <tr>
                <td><strong>Date in: </strong><?php echo $order->getDateRecieved() ?></td>
            </tr>
            <tr>
                <td><strong>Date Due: </strong><?php echo $order->getDateDue() ?></td>
            </tr>
            <tr height="20px"></tr>
        </table>
        <table style="border-collapse: collapse; font-size: 14px;">
            <tr style="border-top: 1px solid black; border-bottom: 1px solid black; font-weight: bold; font-size: 15px; text-align: right;">
		<td width="580px" style="text-align: left;">Product</td>
		<td width="70px">Quantity</td>
            </tr>
            <?php
            foreach($items as $item){
                echo '<tr>';
                echo '<td>'.$item->getName().'</td>';
                echo '<td style="text-align: right;">'.$item->getAmount().'</td>';
                echo '</tr>';
            }
            ?>
            <tr><td height="50px"></td></tr>
            <tr>
                <td>Date:</td>
            </tr>
            <tr>
                <td>__________/______________/_____________</td>
            </tr>
            <tr>
                <td>Signature:</td>
            </tr>
            <tr>
                <td height=20px""></td>
            </tr>
            <tr>
                <td>_____________________________________</td>
            </tr>
        </table>
        <?php
    }
    if($document == 'PoS'){
        //Show Proof of Shipping ?>
        <table style="border-collapse: collapse; font-size: 14px;">
            <tr colspan="5">
                <td style="font-size: 30px;"><strong>Delivery Note</strong></td>
            </tr>
            <tr><td height="40px"></td></tr>
            <tr>
                <td width="325px"><strong>By:</strong></td>
            </tr>
            <tr>
                <td><?php echo $contact->getName() ?></td>
            </tr>
            <tr>
                <td><?php echo $contact->getAddress() ?></td>	
            </tr>
            <tr>
                <td><?php echo $contact->getZipCode().' '.$contact->getCity() ?></td>
            </tr>
            <tr>
                <td><?php echo $contact->getCountry() ?></td>
            </tr>
            <tr height="10px"></tr>
            <tr>
                <td><strong>Phone: </strong><?php echo $contact->getPhone() ?></td>
                <td></td>
            </tr>
            <tr>
                <td><strong>Mobile: </strong><?php echo $contact->getMobile() ?></td>
                <td></td>
            </tr>
            <tr height="10px"></tr>
            <tr>
                <td><strong>Order no: </strong><?php echo $order->getId() ?></td>
                <td><strong>Own No: </strong><?php echo $order->getCOrderNumber() ?></td>
            </tr>
            <tr>
                <td><strong>Date in: </strong><?php echo $order->getDateRecieved() ?></td>
            </tr>
            <tr height="20px"></tr>
    </table>
     <table style="border-collapse: collapse; font-size: 14px;">
            <tr style="border-top: 1px solid black; border-bottom: 1px solid black; font-weight: bold; font-size: 15px; text-align: right;">
		<td width="580px" style="text-align: left;">Product</td>
		<td width="70px">Quantity</td>
            </tr>
            <?php
            foreach($items as $item){
                echo '<tr>';
                echo '<td>'.$item->getName().'</td>';
                echo '<td style="text-align: right;">'.$item->getAmount().'</td>';
                echo '</tr>';
            }
            ?>
            <tr><td height="50px"></td></tr>
            <tr>
                <td>Date:</td>
            </tr>
            <tr>
                <td>__________/______________/___________</td>
            </tr>
            <tr>
                <td>Received by:</td>
            </tr>
            <tr>
                <td>_____________________________________</td>
            </tr>
            <tr>
                <td>Signature:</td>
            </tr>
            <tr>
                <td height=20px""></td>
            </tr>
            <tr>
                <td>_____________________________________</td>
            </tr>
        </table>
        <?php
    }
    if($document == 'Inv'){
        //Show Invoice
        ?>
        <table style="border-collapse: collapse; font-size: 14px;">
            <tr colspan="5">
                <td style="font-size: 30px;"><strong>Invoice</strong></td>
            </tr>
            <tr><td height="40px"></td></tr>
            <tr>
                <td width="325px"><strong>By:</strong></td>
                <td><strong>Shipping to:</strong></td>
            </tr>
            <tr>
                <td><?php echo $contact->getName() ?></td>
                <td><?php echo $order->getShipLastname().' '.$order->getShipFirstname()?></td>
            </tr>
            <tr>
                <td><?php echo $contact->getAddress() ?></td>
                <td><?php echo $order->getShipAddress() ?></td>		
            </tr>
            <tr>
                <td><?php echo $contact->getZipCode().' '.$contact->getCity() ?></td>
                <td><?php echo $order->getShipZipcode().' '.$order->getShipCity() ?></td>
            </tr>
            <tr>
                <td><?php echo $contact->getCountry() ?></td>
                <td><?php echo $order->getShipCountry() ?></td>
            </tr>
            <tr height="10px"></tr>
            <tr>
                <td><strong>Phone: </strong><?php echo $contact->getPhone() ?></td>
                <td></td>
            </tr>
            <tr>
                <td><strong>Mobile: </strong><?php echo $contact->getMobile() ?></td>
                <td></td>
            </tr>
            <tr height="10px"></tr>
            <tr>
                <td><strong>Order no: </strong><?php echo $order->getId() ?></td>
                <td><strong>Own No: </strong><?php echo $order->getCOrderNumber() ?></td>
            </tr>
            <tr>
                <td><strong>Date in: </strong><?php echo $order->getDateRecieved() ?></td>
            </tr>
            <tr height="20px"></tr>
    </table>
    <table style="border-collapse: collapse; font-size: 12px;">
        <tr style="border-top: 1px solid black; border-bottom: 1px solid black; font-weight: bold; font-size: 15px; text-align: right;">
            <td width="360px" style="text-align: left;">Product</td>
            <td width="70px">Quantity</td>
            <td width="70px">Price</td>
            <td width="80px">Discount(%)</td>
            <td width="70px">Total Price</td>
        </tr>
        <?php foreach($items as $item) {
            echo '<tr style="text-align: right;">';
            echo '<td style="text-align: left;">'.$item->getName().'</td>';
            echo '<td>'.$item->getAmount().'</td>';
            echo '<td>'.$item->getPrice().'</td>';
            echo '<td>'.$item->getDiscount().'</td>';
            $total_discount = $item->getDiscount() * $item->getPrice();
            $total_price_product = $item->getAmount() * $item->getPrice() - $total_discount;
            echo '<td>'.$total_price_product.'</td>';
            echo '</tr>';
            //calculate total price
            if(!isset($total_price_order)){ $total_price_order = 0; }
            $total_price_order = $total_price_order + $total_price_product;
            //calculate taxes
            $tax = $item->getVAT();
            $tax_dec = '0.'.$tax; //tax in decimals
            $tax_product = $item->getPrice() * $tax_dec; //tax for 1 product
            $tax_total_products = $item->getAmount() * $tax_product;//tax over all products
            if(!isset($total_tax)){ $total_tax = 0; }
            $total_tax = $total_tax + $tax_total_products;
        } ?>
        <tr height="20px"></tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>	
            <td>Subtotal</td>
            <td style="border-top: 1px solid black; text-align: right;"><?php echo $total_price_order ?></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td>VAT</td>
            <td style="text-align: right;"><?php echo $total_tax ?></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>	
            <td>Total</td>
            <td style="border-top: 1px solid black; text-align:right;"><?php echo $total_price_order + $total_tax ?></td>
        </tr>
        </table>
        <?php
    }

    ?>

</div>
<?php
}
if($document == 'LoM'){
        //Show List of Materials
        ?>
<div style="font-family:calibri;">
        <table style="border-collapse: collapse; font-size: 14px;">
            <tr colspan="5">
                <td style="font-size: 30px;"><strong>Material List</strong></td>
            </tr>
            <tr><td height="40px"></td></tr>
            <tr>
                <td><strong>Order no: </strong><?php echo $order->getId() ?></td>
            </tr>
            <tr>
                <td><strong>Date in: </strong><?php echo $order->getDateRecieved() ?></td>
            </tr>
            <tr height="20px"></tr>
        </table>
        <table style="border-collapse: collapse; font-size: 12px;">
            <tr style="border-top: 1px solid black; border-bottom: 1px solid black; font-weight: bold; font-size: 15px;">
		<td width="155px">Material</td>
		<td width="50px">Needed</td>
		<td width="30px" style="border-left: 1px solid black; padding: 0 5px;">Used</td>
		<td width="55px" style="padding: 0 5px;">Signature</td>
		<td width="30px" style="border-left: 1px solid black; padding: 0 5px;"">Used</td>
		<td width="55px" style="padding: 0 5px;">Signature</td>
		<td width="30px" style="border-left: 1px solid black;padding: 0 5px;"">Used</td>
		<td width="55px" style="padding: 0 5px;">Signature</td>
		<td width="30px" style="border-left: 1px solid black; padding: 0 5px;"">Used</td>
		<td width="55px" style="padding: 0 5px;">Signature</td>
		<td width="30px" style="border-left: 1px solid black; padding: 0 5px;"">Used</td>
		<td width="55px" style="padding: 0 5px;">Signature</td>
                <td width="30px" style="border-left: 1px solid black; padding: 0 5px;"">Used</td>
		<td width="55px" style="padding: 0 5px;">Signature</td>
                <td width="30px" style="border-left: 1px solid black; padding: 0 5px;"">Used</td>
		<td width="55px" style="padding: 0 5px;">Signature</td>
                <td width="30px" style="border-left: 1px solid black; padding: 0 5px;"">Used</td>
		<td width="55px" style="padding: 0 5px;">Signature</td>
                <td width="30px" style="border-left: 1px solid black; padding: 0 5px;"">Used</td>
		<td width="55px" style="padding: 0 5px;">Signature</td>
                <td width="30px" style="border-left: 1px solid black; padding: 0 5px;"">Used</td>
		<td width="55px" style="padding: 0 5px;">Signature</td>
            </tr>
            <?php
            foreach($materials as $material){
                echo '<tr>';
                echo '<td>'.$material->getName().' '.$material->getType().'</td>';
                echo '<td>'.$material->getRequired().'</td>';
                echo '<td style="border-left: 1px solid black;"></td>';
                echo '<td></td>';
                echo '<td style="border-left: 1px solid black;"></td>';
                echo '<td></td>';
                echo '<td style="border-left: 1px solid black;"></td>';
                echo '<td></td>';
                echo '<td style="border-left: 1px solid black;"></td>';
                echo '<td></td>';
                echo '<td style="border-left: 1px solid black;"></td>';
                echo '<td></td>';
                echo '<td style="border-left: 1px solid black;"></td>';
                echo '<td></td>';
                echo '<td style="border-left: 1px solid black;"></td>';
                echo '<td></td>';
                echo '<td style="border-left: 1px solid black;"></td>';
                echo '<td></td>';
                echo '<td style="border-left: 1px solid black;"></td>';
                echo '<td></td>';
                echo '<td style="border-left: 1px solid black;"></td>';
                echo '<td></td>';
                echo '</tr>';
            }                
            ?>
        </table>
</div>
        <?php
    }
?>